import threading
import queue


class Foo:
    def __init__(self):
        self.value = 1
        self.q1 = queue.Queue()
        self.q2 = queue.Queue()
        self.q1.put(0)

    def print1(self):
        while self.value < 100:
            self.q1.get()
            print(f'{threading.current_thread().name}:', self.value)
            self.value += 1
            self.q2.put(0)

    def print2(self):
        while self.value < 100:
            self.q2.get()
            print(f'{threading.current_thread().name}:', self.value)
            self.value += 1
            self.q1.put(0)


if __name__ == '__main__':
    try:
        f = Foo()
        t1 = threading.Thread(target=f.print1, name='thread-1')
        t2 = threading.Thread(target=f.print2, name='thread-2')
        t1.start()
        t2.start()
    except:
        print("Error: 无法启动线程")
